package com.ruanjian.serviceBase;



import com.ruanjian.commonUtils.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.sql.SQLException;

//Aop,controller的增强
@ControllerAdvice
@ResponseBody
public class globalExceptionHandler {


    //指定出现了什么异常执行这个方法
    @ExceptionHandler({Exception.class})

    public R error(Exception e)
    {
        e.printStackTrace();
        return  R.error().Message(e.getMessage());
    }

    @ExceptionHandler({MyException.class})
    public R error(MyException e)
    {
        e.printStackTrace();
        return  R.error().code(e.getCode()).Message(e.getMsg());
    }




}
